package com.tchintech.pay.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tchintech.pay.R;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/12 0012.
 */

public class KeyBoardAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<Map<String, String>> valueList;

    public KeyBoardAdapter(Context mContext, ArrayList<Map<String, String>> valueList) {
        this.mContext = mContext;
        this.valueList = valueList;
    }

    @Override
    public int getCount() {
        return valueList.size();
    }

    @Override
    public Object getItem(int position) {
        return valueList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.grid_item_virtual_keyboard, null);
            viewHolder = new ViewHolder();
            viewHolder.btnKey = (TextView) convertView.findViewById(R.id.btn_keys);
            viewHolder.imgDelete = (RelativeLayout) convertView.findViewById(R.id.imgDelete);
            viewHolder.iv_pay = (ImageView) convertView.findViewById(R.id.iv_pay);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (position == 0) {
            viewHolder.iv_pay.setBackground(ContextCompat.getDrawable(mContext, R.drawable.wxpay));
            viewHolder.imgDelete.setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorWx));
        } else if (position == 1) {
            viewHolder.iv_pay.setBackground(ContextCompat.getDrawable(mContext, R.drawable.zfbpay));
            viewHolder.imgDelete.setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorZfb));
        } else if (position == 2) {
            viewHolder.iv_pay.setBackground(ContextCompat.getDrawable(mContext, R.drawable.unionpay));
            viewHolder.imgDelete.setBackgroundColor(ContextCompat.getColor(mContext, R.color.coloru));
            viewHolder.btnKey.setVisibility(View.INVISIBLE);
        } else if (position < 12) {
            viewHolder.imgDelete.setVisibility(View.INVISIBLE);
            viewHolder.btnKey.setVisibility(View.VISIBLE);
            viewHolder.btnKey.setText(valueList.get(position).get("name"));
            viewHolder.btnKey.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
        } else if (position == 12) {
            viewHolder.imgDelete.setVisibility(View.INVISIBLE);
            viewHolder.btnKey.setVisibility(View.VISIBLE);
            viewHolder.btnKey.setText(valueList.get(position).get("name"));
            viewHolder.btnKey.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
        } else if (position == 13) {
            viewHolder.imgDelete.setVisibility(View.INVISIBLE);
            viewHolder.btnKey.setVisibility(View.VISIBLE);
            viewHolder.btnKey.setText(valueList.get(position).get("name"));
            viewHolder.btnKey.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
        } else if (position == 14) {
            viewHolder.iv_pay.setBackground(ContextCompat.getDrawable(mContext, R.mipmap.keyboard_delete_img));
            viewHolder.btnKey.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
            viewHolder.imgDelete.setVisibility(View.VISIBLE);
        }

        return convertView;
    }

    /**
     * 存放控件
     */
    public final class ViewHolder {
        public TextView btnKey;
        public RelativeLayout imgDelete;
        public ImageView iv_pay;
    }


}
